package com.service.job.pa.support;

import java.util.List;

import com.dao.job.pa.IJobPriviledgeDao;
import com.pojo.job.pa.PAJobPriviledge;
import com.service.basic.ISALMService;
import com.service.job.pa.IJobPriviledgeService;

public class JobPriviledgeService implements IJobPriviledgeService {
	
	private IJobPriviledgeDao jobPriviledgeDao;
	private ISALMService salmService;
	
	//setter getter
	
	public void setJobPriviledgeDao(IJobPriviledgeDao jobPriviledgeDao) {
		this.jobPriviledgeDao = jobPriviledgeDao;
	}

	//service method

	public void setSalmService(ISALMService salmService) {
		this.salmService = salmService;
	}

	public List<PAJobPriviledge> findByRightJoinSALM(Integer PA_MENU_ID,Integer IS_ET) {
		return jobPriviledgeDao.findByRightJoinSALM(PA_MENU_ID,IS_ET);
	}

	public void sava(PAJobPriviledge pjp) {
		jobPriviledgeDao.sava(pjp);
	}

	public void sava(Integer menuid,String datas,Integer IS_ET) {
		this.delete(menuid,IS_ET);
		datas = datas.substring(0, datas.length()-1);
		String [] temps = datas.split(":");
		
		for(int i =0 ; i < temps.length; i++){
			System.out.println(temps.length);
			String priviledges [] = temps[i].split(";");
			PAJobPriviledge pjp = new PAJobPriviledge();
			pjp.setPA_MENU_ID(menuid);
			pjp.setIS_ET(IS_ET);
			pjp.setSALM(salmService.get(priviledges[0]));
			pjp.setPNEW(Integer.parseInt(priviledges[1]));
			pjp.setPREMOVE(Integer.parseInt(priviledges[2]));
			pjp.setPSAVA(Integer.parseInt(priviledges[3]));
			pjp.setPMODIFY(Integer.parseInt(priviledges[4]));
			pjp.setPVIEW(Integer.parseInt(priviledges[5]));
			pjp.setPRIVACY(Integer.parseInt(priviledges[6]));
			this.sava(pjp);
		}
	}

	public void delete(Integer menuId,Integer IS_ET) {
		jobPriviledgeDao.delete(menuId,IS_ET);
	}

}
